package com.compass.doctor.ui.home

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.compass.doctor.databinding.ActivityMyPharmacyBinding
import com.compass.doctor.ui.home.fragment.AllDrugsFragment
import com.compass.doctor.ui.home.fragment.RoutineDrugFragment
import com.compass.framework.adapter.ViewPage2FragmentAdapter
import com.compass.doctor.base.BaseVBActivity
import com.compass.framework.constant.KEY_INDEX

/**
 * Description： 我的药房 (后续扩展)
 * Date:2023/12/7 9:45
 */
class MyPharmacyActivity : BaseVBActivity<ActivityMyPharmacyBinding>() {

    private lateinit var viewPageAdapter: ViewPage2FragmentAdapter
    private var fragments: ArrayList<Fragment> = ArrayList()
    private lateinit var routineDrugFragment: RoutineDrugFragment//常用药品
    private lateinit var allDrugsFragment: AllDrugsFragment//全部药品


    companion object {
        fun start(context: Context, index: Int = 0) {
            val intent = Intent(context, MyPharmacyActivity::class.java)
            intent.putExtra(KEY_INDEX, index)
            context.startActivity(intent)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        initFragment()
        mBinding.dslTab.tabIndicator.indicatorWidth = -2
        mBinding.dslTab.tabIndicator.indicatorEnableFlow = true
        mBinding.dslTab.configTabLayoutConfig {
            onSelectIndexChange = { fromIndex, selectIndexList, reselect, fromUser ->
                val toIndex = selectIndexList.first()
                mBinding.viewpager2.setCurrentItem(toIndex, false)

            }
        }
        viewPageAdapter = ViewPage2FragmentAdapter(supportFragmentManager, lifecycle, fragments)
        mBinding.viewpager2.adapter = viewPageAdapter
        mBinding.viewpager2.isUserInputEnabled = false//禁止viewPage滑动
        mBinding.viewpager2.setCurrentItem(0, false)
    }

    private fun initFragment() {


        routineDrugFragment = RoutineDrugFragment()
        fragments.add(routineDrugFragment)

        allDrugsFragment = AllDrugsFragment()
        fragments.add(allDrugsFragment)


    }
}